<?php
namespace app\common\service;
use app\common\model\settings\Region as RegionModel;
class Region
{
    public static function regionOption()
    {
        $options = cache('region_options');
        if ($options) {
            return Result::success($options);
        }
        $map = [
            ['is_delete', '=', 0]
        ];
        $lists = RegionModel::withoutGlobalScope()->where($map)->field('id,pid,name')->order(['id' => 'asc', 'sort' => 'asc'])->select()->toArray();
        $options = Tree::setConfig('id', 'pid', 'children')->makeTree($lists);
        cache('region_options', $options);
        return Result::success($options);
    }
}